import { Component, OnInit } from "@angular/core";
import { Subscription } from "rxjs";
import {
  Router,
  ActivatedRoute,
  ActivatedRouteSnapshot,
  RouterState,
  RouterStateSnapshot
} from "@angular/router";
import { SignInService } from "../../user/sign-in/sign-in.service";

@Component({
  selector: "app-post-detail-main",
  templateUrl: "./post-detail-main.component.html",
  styleUrls: ["./post-detail-main.component.scss"]
})
export class PostDetailMainComponent implements OnInit {
  private subscription: Subscription;

  constructor(
    public router: Router,
    public activatedRoute: ActivatedRoute,
    public signInService: SignInService
  ) {}

  ngOnInit(): void {
    this.subscription = this.signInService.currentUser.subscribe(data => {
      let activatedRouteSnapshot: ActivatedRouteSnapshot = this.activatedRoute
        .snapshot;
      let routerState: RouterState = this.router.routerState;
      let routerStateSnapshot: RouterStateSnapshot = routerState.snapshot;

      if (routerStateSnapshot.url.includes("/login")) {
        alert("用户登录成功，可以隐藏登录面板了！");
      }
    });
  }

  ngOnDistroy() {
    this.subscription.unsubscribe();
  }
}
